/**
* File:StopwatchLAP.h 
* The definition to view Lap records
*
* Copyright (c) 2008, J PENG
* All rights reserved.
**/

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace PJJTimer {

	/// <summary>
	/// Summary for StopwatchLAP
	///
	/// A simple class to display Lap records in a ListView control and the ability to convert/save it
	/// into text file.
	/// </summary>
	public ref class StopwatchLAP : public System::Windows::Forms::Form
	{
	public:
		StopwatchLAP()
		{
			InitializeComponent();
			if(language != Languages::English) SetLanguages();
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~StopwatchLAP()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::ListView^  lapListView;
	private: System::Windows::Forms::ColumnHeader^  columnHeader_no;
	private: System::Windows::Forms::ColumnHeader^  columnHeader_lap;
	private: System::Windows::Forms::ColumnHeader^  columnHeader_time;

	private:
		System::Windows::Forms::ImageList^ imageset;
		System::Windows::Forms::ListViewItem^ lapItem;
		System::Windows::Forms::ColumnHeader^  columnHeader_extraInfo;
		System::Windows::Forms::Button^  button_save;

	private: System::Windows::Forms::ToolTip^  tips;
	private: System::Windows::Forms::Button^  button_clear;
	private: System::ComponentModel::IContainer^  components;


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(StopwatchLAP::typeid));
			this->lapListView = (gcnew System::Windows::Forms::ListView());
			this->columnHeader_no = (gcnew System::Windows::Forms::ColumnHeader());
			this->columnHeader_lap = (gcnew System::Windows::Forms::ColumnHeader());
			this->columnHeader_time = (gcnew System::Windows::Forms::ColumnHeader());
			this->columnHeader_extraInfo = (gcnew System::Windows::Forms::ColumnHeader());
			this->button_save = (gcnew System::Windows::Forms::Button());
			this->tips = (gcnew System::Windows::Forms::ToolTip(this->components));
			this->button_clear = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// lapListView
			// 
			this->lapListView->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^  >(4) {this->columnHeader_no, 
				this->columnHeader_lap, this->columnHeader_time, this->columnHeader_extraInfo});
			this->lapListView->Dock = System::Windows::Forms::DockStyle::Top;
			this->lapListView->FullRowSelect = true;
			this->lapListView->GridLines = true;
			this->lapListView->HeaderStyle = System::Windows::Forms::ColumnHeaderStyle::Nonclickable;
			this->lapListView->Location = System::Drawing::Point(0, 0);
			this->lapListView->MultiSelect = false;
			this->lapListView->Name = L"lapListView";
			this->lapListView->ShowItemToolTips = true;
			this->lapListView->Size = System::Drawing::Size(374, 164);
			this->lapListView->TabIndex = 0;
			this->lapListView->UseCompatibleStateImageBehavior = false;
			this->lapListView->View = System::Windows::Forms::View::Details;
			// 
			// columnHeader_no
			// 
			this->columnHeader_no->Text = L"No.";
			this->columnHeader_no->Width = 40;
			// 
			// columnHeader_lap
			// 
			this->columnHeader_lap->Text = L"LAP";
			this->columnHeader_lap->Width = 120;
			// 
			// columnHeader_time
			// 
			this->columnHeader_time->Text = L"Capture Time";
			this->columnHeader_time->Width = 120;
			// 
			// columnHeader_extraInfo
			// 
			this->columnHeader_extraInfo->Text = L"Extra Info";
			this->columnHeader_extraInfo->Width = 65;
			// 
			// button_save
			// 
			this->button_save->Cursor = System::Windows::Forms::Cursors::Hand;
			this->button_save->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"button_save.Image")));
			this->button_save->Location = System::Drawing::Point(160, 168);
			this->button_save->Name = L"button_save";
			this->button_save->Size = System::Drawing::Size(24, 22);
			this->button_save->TabIndex = 1;
			this->tips->SetToolTip(this->button_save, L"Save to text file");
			this->button_save->UseVisualStyleBackColor = true;
			this->button_save->Click += gcnew System::EventHandler(this, &StopwatchLAP::button_save_Click);
			// 
			// tips
			// 
			this->tips->AutomaticDelay = 2000;
			this->tips->AutoPopDelay = 5000;
			this->tips->InitialDelay = 2000;
			this->tips->ReshowDelay = 1000;
			// 
			// button_clear
			// 
			this->button_clear->Cursor = System::Windows::Forms::Cursors::Hand;
			this->button_clear->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"button_clear.Image")));
			this->button_clear->Location = System::Drawing::Point(190, 168);
			this->button_clear->Name = L"button_clear";
			this->button_clear->Size = System::Drawing::Size(24, 22);
			this->button_clear->TabIndex = 1;
			this->tips->SetToolTip(this->button_clear, L"Clear all records (will reset the stopwatch)");
			this->button_clear->UseVisualStyleBackColor = true;
			this->button_clear->Click += gcnew System::EventHandler(this, &StopwatchLAP::button_clear_Click);
			// 
			// StopwatchLAP
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(374, 193);
			this->Controls->Add(this->button_clear);
			this->Controls->Add(this->button_save);
			this->Controls->Add(this->lapListView);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
			this->Name = L"StopwatchLAP";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L" Stopwatch LAP View";
			this->ResumeLayout(false);

		}
#pragma endregion

	public:
		void SetLanguages();
		//Add a lap capture object to the collection
		void CaptureLAP(String^ lap, bool running);
		// Clear all LAP records currently holding
		void ClearLapRecords(void);
		// Capture the beginning Lap info
		void CaptureBeginningLAP(void);
		// Enable 'Save', 'Print' and 'Clear' buttons
		void EnableAllButtons(void);
		// Disable 'Save', 'Print' and 'Clear' buttons
		void DisableAllButtons(void);

	private:
		System::Void button_clear_Click(System::Object^  sender, System::EventArgs^  e);
		System::Void button_save_Click(System::Object^  sender, System::EventArgs^  e);

	public:
		// Enable buttons if any records exist and disable them otherwise
		void InitializeButtonsBeforeShowing(void);
		// Get the number of records from the LAP collection
		int GetLapRecords(void);
		void SaveLapsToTextFile(String^ path);

};
}
